package org.example.reactive.demo1.handler;

import lombok.RequiredArgsConstructor;
import org.example.reactive.demo1.entity.Employer;
import org.example.reactive.demo1.repository.EmployerRepository;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * @author Gong.Yang
 */
@Component
@RequiredArgsConstructor
public class EmployerHandler {
    private final EmployerRepository employerRepository;

    public Mono<ServerResponse> findById(ServerRequest request) {
        String id = request.pathVariable("id");
        Mono<Employer> byId = employerRepository.findById(id);
        return ServerResponse.ok().body(byId, Employer.class);
    }
}
